//index.js
//获取应用实例
var app = getApp();
const utils = require('../../utils/util');
Page({
    data: {
        modalHidden: true,
        nickName: "",
        avatarUrl: "",
        finishedWord:0,
        // userInfo: {
        //     nickName:"",
        //     avatarUrl:""
        // },
        inputname: "",
        studiedDays: 0
    },

    onLoad: function() {
        console.log('onLoad')
        var that = this
        app.getUserInfo(function(userInfo) {
                that.setData({
                    nickName: userInfo.nickName,
                    avatarUrl: userInfo.avatarUrl
                })
        })
    },
    login: function() {
        this.setData({
            modalHidden: false
        })
    },
    saveInput: function(e) {
        this.setData({
            inputname: e.detail.value
        });
    },
    actionConfirm: function(e) {
        var that = this
        wx.setStorageSync('username', this.data.username);
        wx.setStorageSync('password', this.data.password);
        this.setData({
            modalHidden: true,
            nickName: that.data.inputname
        })
    },
    actionCancel: function() {
        this.setData({
            modalHidden: true
        })
    },

    aboutBtn: function() {
        wx.navigateTo({
          url: '../about/about',
        });
    },
    onShow: function() {
        var that = this
        setTimeout(function() {
            let finishedWord = 0;
            let words = wx.getStorageSync(utils.wordBook);
            let studiedDays = wx.getStorageSync(utils.studiedDays);
            console.log('my page ',studiedDays);
            that.setData({
                studiedDays: Number.parseInt(studiedDays)
            });
            if(words === null || words === undefined || words === '') {
               finishedWord = 0;
            } else {
               finishedWord = words.length;
            }
            that.setData({
                finishedWord:finishedWord
            });
        }, 1000);
     },
     gotoWordlib: function() {
         wx.navigateTo({
           url: '../wordlib/wordlib',
         })
     },
     notificationBtn: function() {
         wx.navigateTo({
           url: '../notification/notification',
         });
     },
     passedWordsBtn: function() {
         wx.navigateTo({
           url: '../passed-words/passed-words',
         });
     },
     feedbackBtn: function() {
         wx.navigateTo({
           url: '../feedback/feedback',
         });
     },

     settingBtn: function(){
         wx.navigateTo({
           url: '../setting/setting',
         })
     }



})
